from appium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

desired_caps = {
    'platformName':'Android',
    'platformVersion': '7.1.2',
    'deviceName': 'emulator-5554',
    'appPackage': 'com.android.settings',
    'appActivity': '.Settings'
}
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
time.sleep(1)
# 隐式等待
driver.implicitly_wait(10)
#
# # 点击-放大镜
# # driver.find_element(By.ID, "com.android.settings:id/search").click()
# driver.find_element(By.XPATH, "//*[@resource-id='com.android.settings:id/search']").click()
# time.sleep(2)
# # 输入坚果
# # driver.find_element(By.CLASS_NAME, "android.widget.EditText").send_keys("坚果")
# driver.find_element(By.XPATH, "//*[@class='android.widget.EditText']").send_keys("坚果")

# # 点击wlan，使用元素的文本去找，跟UI区别在于，text()='xxx'，@text='xxx'
# driver.find_element(By.XPATH, "//*[@text='WLAN']").click()

# 显式等待
# 输入坚果
# driver.find_element(By.XPATH, "//*[@class='android.widget.EditText']").send_keys("坚果")
ele = WebDriverWait(driver, 10, 0.5).until(EC.presence_of_element_located((By.XPATH, "//*[@class='android.widget.EditText']")))
ele.send_keys("坚果")

time.sleep(5)
driver.quit()